package cn.shop.dys.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import java.util.List;

import cn.shop.dys.bean.AddressInfo;
import cn.shop.lib_common.CommonViewHolder;
import cn.shop.dys.R;

/**
 * 地址适配器
 * Created by sunjian on 2016/4/19.
 */
public class AddressAdapter extends BaseAdapter{
    private List<AddressInfo> mAddressInfos;
    private Context mContext;

    public AddressAdapter(List<AddressInfo> mAddressInfos, Context mContext) {
        this.mAddressInfos = mAddressInfos;
        this.mContext = mContext;
    //    Log.d("test", "hehe2" + mAddressInfos.toString());
    }

    @Override
    public int getCount() {
        return mAddressInfos==null?0:mAddressInfos.size();
    }

    @Override
    public AddressInfo getItem(int position) {
        return mAddressInfos.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        CommonViewHolder holder = CommonViewHolder.getCommonViewHolder(convertView, mContext, R.layout.user_item_address_list);
        AddressInfo addressInfo = mAddressInfos.get(position);
      //  Log.d("test", "hehe2" + addressInfo.toString());
        holder.getTv(R.id.tv_address_list_user_name).setText(addressInfo.getName());
        holder.getTv(R.id.tv_address_list_phone).setText(addressInfo.getPhoneNumber());
        holder.getTv(R.id.tv_address_list_detail_address).setText(addressInfo.getProvince() +
                addressInfo.getCity() + addressInfo.getAddressArea() + addressInfo.getAddressDetail());
        int isDefault = addressInfo.getIsDefault();
        if(isDefault==0){
            holder.getTv(R.id.tv_address_list_is_default).setVisibility(View.GONE);
        }else if(isDefault==1){
            holder.getTv(R.id.tv_address_list_is_default).setVisibility(View.VISIBLE);
        }
       // holder.getIv(R.id.iv_address_list_go)
        return holder.convertView;
    }
}
